package com.java.base.exercise;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * @Author RenPu
 * @Date 2021/12/30 9:45
 * @Version 1.0
 * @Description: 使用枚举类优化,if -else或者switch catch
 **/
public class zker {

    @Getter
    @AllArgsConstructor
    public enum ProductIn{
        ZAN_CUN(0,"暂存"),
        YI_TI(1,"已提交"),
        YI_QUE(2,"已确认"),
        YI_JIAN(3,"已质检"),
        YI_BO(4,"被驳回"),
        QUE_REN(5,"入库确认");
        private final Integer code;
        private final String desc;


        public static String traverseValue(Integer code) {
            if(Objects.isNull(code)){
                return null;
            }

            for (ProductIn productInEnum : ProductIn.values()) {
                if (productInEnum.getCode().equals(code)) {
                    return productInEnum.getDesc();
                }
            }
            throw new IllegalArgumentException(String.format("%s 非法的 statusCode",code));
        }


    }


    public static void main(String[] args) {
        for (int i = 0; i <10 ; i++) {
            String s = ProductIn.traverseValue(i);

            System.out.println(s);
        }

    }


}
